const app = getApp();
const util = require('../../../utils/util.js');
Page({
  data: {
    lists: [],

  },
  onLoad: function () {
  },
  onShow:function(){
    app.request('/Insurance/Draft', 'GET', { userId: app.globalData.userId, page: 1, pageSize: 10 },
      res => {
        res.list.forEach(item => {
          item.activeDotList = util.createDotList(3, item.step);
        });
        console.log(res.list);
        this.setData({
          lists: res.list
        });
      }, '获取保险信息失败');
  },
  deleteLists: function (e) {
    var that = this;
    var lists = this.data.lists;
    var index = e.currentTarget.dataset.index;
    wx.showModal({
      title: '提示',
      content: '确定要删除吗？',
      success: function (res) {
        if (res.confirm) {
          console.log('点击确定了');
          app.request('/Insurance/Delete', 'DELETE', [e.currentTarget.id],
            res => {
              wx.showToast({
                title: '删除成功',
                success: res => {
                  lists.splice(index, 1);
                  that.setData({
                    lists: lists,
                  });
                }
              })
            }, '删除失败');
        } else if (res.cancel) {
          console.log('点击取消了');
          return false;
        }
      }
    })
  },
  addList: function () {
    wx.navigateTo({ url: '../detail/detail' });
  },
  goToviPage: function (e) {
    wx.navigateTo({ url: `../detail/detail?insuranceQuotationId=${e.currentTarget.id}`});
  },

  goToDetail: function (e) {
    wx.navigateTo({ url: `../../order/insuranceQuotation/insuranceQuotation?quotationId=${e.currentTarget.id}` });
  }
})